with Ada.Real_Time;
use Ada.Real_Time;

with Ada.Text_IO;

with Epoch;

package body CyclicTask is

   task body Cyclic is
      Next_Period : Ada.Real_Time.Time;
      Period : constant Ada.Real_Time.Time_Span :=
        Ada.Real_Time.Microseconds(Cycle_Time);

      -- Other declarations

      Increment : Positive;
      package X_IO is new Ada.Text_IO.Integer_IO(Positive);
      use X_IO;
   begin
      -- Initialization code

      Increment := 1;


      Epoch.Epoch.Get_Start_Time(Next_Period);
      Next_Period := Next_Period + Period;
      loop

         delay until Next_Period; -- wait until next period after epoch
                                  -- Non-suspending periodic response code
                                  -- May include calls to protected procedures

         Ada.Text_IO.Put("Task ");
         X_IO.Put(Item => Id, Width => 3, Base => 10);
         Ada.Text_IO.Put("  -> Incrementador = ");
         X_IO.Put(Item => Increment, Width => 3, Base => 10);
         Ada.Text_IO.Put_Line("");

         Next_Period := Next_Period + Period;
         Increment := Increment + 1;

      end loop;
   end Cyclic;

end CyclicTask;
